# -*- coding: utf-8 -*-
# 服务器端，用以处理五子棋棋盘信息通信
from flask import Flask, request

app = Flask(__name__)

# board = [[0, 0, 0],
#          [0, 1, 0],
#          [1, 2, 0]]
LINES = 19
board = [[0] * LINES for _ in range(LINES)]  # 生成[LINESxLINES]矩阵

board_dict = {'board': board,
              'runner': 'black'}


@app.route('/')
def index():
    return "Hello Goumuku!"


@app.route('/board', methods=['GET'])
def getBoard():
    return board_dict


@app.route('/board', methods=['POST'])
def setBoard():
    global board, board_dict

    new_board = request.form.getlist('board')
    new_runner = request.form['runner']
    # print(new_board)

    i = 0
    board_length = len(board)
    for row in range(board_length):
        for col in range(board_length):
            board[row][col] = int(new_board[i])
            i += 1
            pass
        pass

    # print(board)
    board_dict['board'] = board
    board_dict['runner'] = new_runner
    return 'successfully post'


if __name__ == '__main__':
    # app.run(host='0.0.0.0', port='5000')
    app.run(port='5000')
    pass
